<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:h="http://java.sun.com/jsf/html"
        xmlns:icecore="http://www.icefaces.org/icefaces/core"
       xmlns:ace="http://www.icefaces.org/icefaces/components"
       xmlns:ice="http://www.icesoft.com/icefaces/component"
       xmlns:c="http://java.sun.com/jsp/jstl/core">      
    <h:head>
        <title><h:form><h:outputText>Vorlesung #{lectureBean.lecture.name} Belegwünsche anzeigen</h:outputText></h:form></title>
    </h:head>
    <h:body>
        <ui:composition template="WEB-INF/templates/lecture.xhtml">                        
            <ui:define name="content">
                <h:form>
                    <ice:outputText value="Neue Kategorie hinzufügen"/>
                    <ice:inputText value="#{downloadPageBean.newCategoryName}" /><br />
                    <ice:commandButton value="Erstellen"
                                       action="#{lectureBean.lecture.addDownloadCategory(downloadPageBean.newCategoryName)}"
                                       partialSubmit="true"/>
                </h:form>
                <br />
                <br />
                    <h:form>
                    <ice:outputText value="Neuen Download erstellen" />
                    <br />
                    <ice:outputText value="Linkname" />
                    <ice:inputText value="#{downloadPageBean.newDownloadName}" />
                    <br />
                    <ice:outputText value="Kategorie" />
                    <ice:selectOneMenu value="#{downloadPageBean.newDownloadCategory}"
                                       converter="downloadCategoryConverter">
                        <f:selectItems value="#{downloadPageBean.downloadItems}" />
                    </ice:selectOneMenu>
                    <br />
                    <ice:outputText value="Externer Link?" />
                    <ice:selectBooleanCheckbox value="#{downloadPageBean.isExternalLink}"
                                               partialSubmit="true"/>
                    <br />
                    <ice:outputText value="Externe URL" 
                                    rendered="#{downloadPageBean.isExternalLink}"/>
                    <ice:inputText value="#{downloadPageBean.externalLink}" 
                                   rendered="#{downloadPageBean.isExternalLink}"/>
                    <ice:outputText value="Datei hochladen"
                                    rendered="#{!downloadPageBean.isExternalLink}"/>
                    <ice:outputText value="Hochgeladen"
                                    rendered="#{downloadPageBean.resource != null}" />
                    <!-- TODO: FileChangeListener-->
                    <ace:fileEntry rendered="#{!downloadPageBean.isExternalLink}"
                                   fileEntryListener="#{downloadPageBean.uploadListener}"
                                   />
                    <h:commandButton value="hochladen"/>

                    <br />
                    <br />
                        <ice:commandButton value="Hinzufügen"
                                       action="#{downloadPageBean.addDownload()}" 
                                       partialSubmit="true"/>
                
                        </h:form>
                <ice:panelGroup rendered="#{lectureBean.hasEditRights()}">
               <c:forEach items="#{lectureBean.lecture.downloads}"
                          var="d">
                        <ice:column>
                            <f:facet name="header"><ice:outputText value="Kategorie Name" /></f:facet>
                            <br />
                            <ice:outputText value="Kategorie: " /><ice:inputText value="#{d.name}" />
                        </ice:column>
                        <ice:column>
                            <f:facet name="header"><ice:outputText value="Downloads" /></f:facet>
                            <ice:dataTable value="#{d.downloads}"
                                           var="elem">
                                <ice:column>                                    
                                    <f:facet name="header"><ice:outputText value="Name" /></f:facet>
                                    <h:form>
                                        <ice:inputText value="#{elem.name}"
                                                       partialSubmit="true"/>
                                    </h:form>     
                                </ice:column>
                                <ice:column>
                                    <f:facet name="header"><ice:outputText value="Externer Link?"/></f:facet>
                                    <h:form>
                                        <ice:selectBooleanCheckbox value="#{elem.isExternalLink}" 
                                                                   partialSubmit="true"/>
                                    </h:form>
                                </ice:column>                                
                                <ice:column>
                                    <f:facet name="header"><ice:outputText value="File" /></f:facet>
                                    <h:form>
                                        <ice:outputText value="externer Link"
                                                        rendered="#{elem.isExternalLink}"/>
                                        <ice:inputText value ="#{elem.externalLink}" 
                                                       rendered="#{elem.isExternalLink}"
                                                       partialSubmit="true"/>
                                        <!--TODO: FileListener implementieren -->
                                        <ace:fileEntry rendered="#{!elem.isExternalLink}"/>
                                        <h:commandButton value="hochladen"
                                                         rendered="#{!elem.isExternalLink}"/>
                                    </h:form>
                                </ice:column>
                                <ice:column>
                                    <h:form>
                                        <ice:commandLink value="hoch"
                                                         action="#{d.moveDownloadUp(elem)}" />
                                    </h:form>
                                </ice:column>
                                <ice:column>
                                    <h:form>
                                        <ice:commandLink value="runter"
                                                         action="#{d.moveDownloadDown(elem)}" />
                                    </h:form>
                                </ice:column>
                                <ice:column>
                                    <h:form>
                                        <ice:commandLink value="Löschen"
                                                         action="#{d.removeDownload(elem)}" />
                                    </h:form>    
                                </ice:column>
                            </ice:dataTable>
                        </ice:column>
                    </c:forEach>
                </ice:panelGroup>
                <br />
                <br />
                <c:forEach  items="#{lectureBean.lecture.downloads}"
                               var="d">
                    <br />
                    <ice:outputText value="#{d.name}" />
                        <ice:panelSeries value="#{d.downloads}"
                                       var="elem"
                                       id="icefacesSucks#{d.name}">
                                <ice:outputResource rendered="#{!elem.isExternalLink}"
                                                    resource="#{downloadPageBean.getResource(elem.resource)}"
                                                    fileName="#{elem.filename}"
                                                    label="    #{elem.name}"
                                                    type="link"
                                                    />
                                <ice:outputLink target="_blank"
                                                rendered="#{elem.isExternalLink}"
                                                value="#{elem.externalLink}"
                                                >#{elem.name}
                                </ice:outputLink>                                
                        </ice:panelSeries>
                </c:forEach>
            </ui:define>
        </ui:composition>
    </h:body>
</html>